package com.peng.sell.handler;

import com.peng.sell.config.ProjectUrlConfig;
import com.peng.sell.enums.ResponseCodeEnum;
import com.peng.sell.exception.SellException;
import com.peng.sell.exception.SellerAuthorizeException;
import com.peng.sell.vo.ServerResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

@ControllerAdvice
public class SellerExceptionHandler {

    @Autowired
    private ProjectUrlConfig projectUrlConfig;

    /**
     * 登录权限异常处理
     * @return
     */
    @ExceptionHandler(SellerAuthorizeException.class)
    public String handleAuthorizeException(){
        System.out.println("假装拦截了没有登录，并将他送到了二维码登录的地方。。。OS:我又没有微信企业号");
        return "redirect:"+projectUrlConfig.getWechatOpenAuthorize()+"/sell/wechat/qr_authorize?returnUrl="+projectUrlConfig.getSell()+"/sell/seller/login";
    }

    /**
     * 商品系统异常处理
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ServerResponseVO handleException(SellException e){
        return ServerResponseVO.createByError(e.getCode(),e.getMessage());
    }
}
